-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementation scaling mode dynamic android and ios #270
implementation scaling mode dynamic android and ios #270
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request. After careful consideration, we believe the proposed approach of mutating the player
's sytyleConfig
is not desirable:
- changes will not be taken into account by the player (player events will not be triggered)
- the scaling mode is a property of the
PlayerView
, not thePlayer
- React Native doesn't allow UI side-effects in
@ReactMethod
,UIManager
has to be used instead.
Here follows our recommendation to implement PlayerView
's ScalingMode
. As the scaling mode property is similar to the fullscreen one, we have used it as an example for each step.
- Add a
scalingMode
parameter to thePlayerView
function andPlayerViewProps
bitmovin-player-react-native/src/components/PlayerView/index.tsx
Lines 87 to 93 in a726523
export function PlayerView({ style, player, fullscreenHandler, customMessageHandler, isFullscreenRequested = false, ...props
- Add a
useEffect
block dispatching a newsetScalingMode
command at the end of thePlayerView
function (after and similarly tosetFullscreen
)bitmovin-player-react-native/src/components/PlayerView/index.tsx
Lines 165 to 170 in a726523
useEffect(() => { const node = findNodeHandle(nativeView.current); if (node) { dispatch('setFullscreen', node, isFullscreenRequested); } }, [isFullscreenRequested, nativeView]);
- Update the Kotlin and Swift code to handle this new message in
RNPlayerViewManager
(similar to thesetFullscreen
method)- call
view.playerView.setScalingMode
in thesetScalingMode
implementation - Kotlin:
Lines 169 to 173 in a726523
Commands.SET_FULLSCREEN -> { args?.getBoolean(1)?.let { isFullscreen -> setFullscreen(view, isFullscreen) } } Lines 185 to 197 in a726523
private fun setFullscreen(view: RNPlayerView, isFullscreen: Boolean) { if (view.playerView?.isFullscreen == isFullscreen) return Handler(Looper.getMainLooper()).post { with(view.playerView ?: return@post) { if (isFullscreen) { enterFullscreen() } else { exitFullscreen() } } } }
- Swift:
bitmovin-player-react-native/ios/RNPlayerViewManager.m
Lines 65 to 68 in a726523
RCT_EXTERN_METHOD(attachPlayer:(nonnull NSNumber *)viewId playerId:(NSString *)playerId playerConfig:(nullable NSDictionary *)playerConfig) RCT_EXTERN_METHOD(attachFullscreenBridge:(nonnull NSNumber *)viewId fullscreenBridgeId:(NSString *)fullscreenBridgeId) RCT_EXTERN_METHOD(setCustomMessageHandlerBridgeId:(nonnull NSNumber *)viewId customMessageHandlerBridgeId:(NSString *)fullscreenBridgeId) RCT_EXTERN_METHOD(setFullscreen:(nonnull NSNumber *)viewId isFullscreen:(BOOL)isFullscreen) bitmovin-player-react-native/ios/RNPlayerViewManager.swift
Lines 74 to 94 in a726523
@objc func setFullscreen(_ viewId: NSNumber, isFullscreen: Bool) { bridge.uiManager.addUIBlock { [weak self] _, views in guard let self, let view = views?[viewId] as? RNPlayerView else { return } guard let playerView = view.playerView else { return } guard playerView.isFullscreen != isFullscreen else { return } if isFullscreen { playerView.enterFullscreen() } else { playerView.exitFullscreen() } } }
- call
Good morning, @krocard, thanks for your support, regarding the possibility of Dynamic Scaling Mode, we have updated the PR with the implementation for both platforms, I would like the BM team to review the code and any comments are welcome, this would help us a lot if you can generate a new version to remove the temporary fix that we added in our application and not have the need to destroy the player as we have said before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for the improvements. I'll let @rolandkakonyi review the Swift side.
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Outdated
Show resolved
Hide resolved
…ViewManager.kt Co-authored-by: Kevin Rocard <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job @jonathanm-tkf!
Please see my comments.
Co-authored-by: Roland Kákonyi <[email protected]>
Co-authored-by: Roland Kákonyi <[email protected]>
Co-authored-by: Roland Kákonyi <[email protected]>
Thank you very much for the recommendations @krocard @rolandkakonyi I have confirmed it locally and it works perfectly, again thank you very much for the help. |
Description
Currently, we don't have the possibility to change the Scaling Mode like on other platforms, similar to the fullscreen button.
Changes